/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Alertas;

import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author Luis
 */
public class Mailer {

    public void enviarMail(String asunto, String mensaje, String destino) throws MessagingException{
     
            Properties props = new Properties();
            props.put("mail.smtp.host", "smtp.gmail.com");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.port", "587");
            props.put("mail.smtp.user", "sensordata.mendoza@gmail.com");
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.ssl.trust", "smtp.gmail.com");

            // Preparamos la sesion
            Session session = Session.getDefaultInstance(props);
            // Construimos el mensaje
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress("sensordata.mendoza@gmail.com"));
            message.addRecipient(
                    Message.RecipientType.TO,
                    new InternetAddress(destino));
            message.setSubject(asunto);
            message.setText(mensaje);
            // Lo enviamos.
            Transport t = session.getTransport("smtp");
            t.connect("sensordata.mendoza@gmail.com", "sensor123");
            t.sendMessage(message, message.getAllRecipients());
            // Cierre.
            t.close();
      
    }
}